#ifndef __W6100_INIT_H_
#define __W6100_INIT_H_
#include "w6100.h"
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include "FreeRTOS.h"
#include "semphr.h"

#define ON   1
#define OFF  0
#define HIGH 1
#define LOW  0


#define AS_IPV4   2
#define AS_IPV6   23
#define AS_IPDUAL 11

#define _LOOPBACK_DEBUG_ 1024
#ifndef DATA_BUF_SIZE
#define DATA_BUF_SIZE 2048
#endif

extern SemaphoreHandle_t w6100_op_xStaticMutex;

int vCreateW6100StaticMutex(void);

void Set_Network(void);
void Reset_W6100(void);
void dhcp_set_network(void);

uint16_t ATOI(char *str, uint16_t base);   /* Convert a string to integer number */
uint32_t ATOI32(char *str, uint16_t base); /* Convert a string to integer number */
void itoa(uint16_t n, uint8_t *str, uint8_t len);
int ValidATOI(char *str, int base, int *ret); /* Verify character string and Convert it to (hexa-)decimal. */
char C2D(uint8_t c);                          /* Convert a character to HEX */

uint16_t swaps(uint16_t i);
uint32_t swapl(uint32_t l);

void replacetochar(char *str, char oldchar, char newchar);

//void mid(int8_t* src, int8_t* s1, int8_t* s2, int8_t* sub);
void inet_addr_(unsigned char *addr, unsigned char *ip);

char *inet_ntoa(unsigned long addr); /* Convert 32bit Address into Dotted Decimal Format */
char *inet_ntoa_pad(unsigned long addr);

//unsigned long inet_addr(unsigned char* addr);		/* Converts a string containing an (Ipv4) Internet Protocol decimal dotted address into a 32bit address */

char VerifyIPAddress_orig(char *src); /* Verify dotted notation IP address string */
char VerifyIPAddress(char *src, uint8_t *ip);
//unsigned long GetDestAddr(SOCKET s);			/* Output destination IP address of appropriate channel */
//unsigned int GetDestPort(SOCKET s);			/* Output destination port number of appropriate channel */
unsigned short htons(unsigned short hostshort);       /* htons function converts a unsigned short from host to TCP/IP network byte order (which is big-endian).*/
unsigned long htonl(unsigned long hostlong);          /* htonl function converts a unsigned long from host to TCP/IP network byte order (which is big-endian). */
unsigned long ntohs(unsigned short netshort);         /* ntohs function converts a unsigned short from TCP/IP network byte order to host byte order (which is little-endian on Intel processors). */
unsigned long ntohl(unsigned long netlong);           /* ntohl function converts a u_long from TCP/IP network order to host byte order (which is little-endian on Intel processors). */
unsigned char CheckDestInLocal(unsigned long destip); /* Check Destination in local or remote */

//SOCKET getSocket(unsigned char status, SOCKET start); 	/* Get handle of socket which status is same to 'status' */
//unsigned short checksum(unsigned char * src, unsigned int len);		/* Calculate checksum of a stream */

#endif
